#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

int main(int argc, char const* argv[])
{
    struct stat st;
    char *type, *readok;

    if (argc != 2)
    {
        printf("usage :%s fd\n", argv[0]);
        exit(1);
    }

    if (fstat(atoi(argv[1]), &st) < 0)
    {
        perror("stat error");
        exit(1);
    }

    if (S_ISREG(st.st_mode))
        type = "regular";
    else if (S_ISDIR(st.st_mode))
        type = "directory";
    else
        type = "other";

    if (st.st_mode & S_IRUSR)
        readok = "yes";
    else
        readok = "no";


    printf("type: %s, read: %s\n", type, readok);

    return 0;
}
